package Listeners;

import java.awt.event.ActionEvent;
import javax.swing.AbstractAction;
import javax.swing.JTextField;

import GUI.ConferenceListPanel;
import GUI.ConferenceWizardFrame;
import Model.ConferenceManager;

/**
 * Listener Used for the "Login" button in the
 * LoginPanel.  Allowing a user to log-in (access)
 * to the system if enter a valid Username.
 * 
 * @author Paul Schultz (ps87@uw.edu)
 * @author Nathan Judkins (nate001@.uw.edu)
 * @version 11/24/2012
 */
@SuppressWarnings("serial")
public class LoginListener extends AbstractAction
{
  private ConferenceWizardFrame my_frame;
  private ConferenceManager my_manager;
  private JTextField my_field;
  
  /**
   * Constructs a new LoginListener.
   * 
   * @author Paul Schultz (ps87@uw.edu)
   * @param the_manager The ConferenceManager that holds the system data.
   * @param the_frame The master frame for this application.
   * @param the_field The textfield holding the user input (presumed a valid username).
   */
  public LoginListener(ConferenceManager the_manager, ConferenceWizardFrame the_frame, JTextField the_field) 
  {
    my_frame = the_frame;
    my_manager = the_manager;
    my_field = the_field;
  }

  /**
   * Take the user to the ConferenceListPanel if they
   * enter a valid username that is registered with the
   * program.
   * 
   * @author Nathan Judkins
   */
  @Override
  public void actionPerformed(ActionEvent arg0)
  {
    String userInput = my_field.getText();
    
    if (my_manager.login(userInput))
    {      
      my_frame.setCurrentPanel(new ConferenceListPanel(my_manager, my_frame));
    }
  }

}
